﻿<UserControl 
    x:Class="TfsWorkbench.NotePadUI.UIElements.UIWorkbenchItem"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:scratchPadUi="clr-namespace:TfsWorkbench.NotePadUI"
    xmlns:uiElements="clr-namespace:TfsWorkbench.UIElements;assembly=TfsWorkbench.UIElements"
    xmlns:valueConverters="clr-namespace:TfsWorkbench.UIElements.ValueConverters;assembly=TfsWorkbench.UIElements"
    xmlns:helpers="clr-namespace:TfsWorkbench.NotePadUI.Helpers"
    xmlns:models="clr-namespace:TfsWorkbench.NotePadUI.Models"
    mc:Ignorable="d" 
    d:DesignHeight="350"
    d:DesignWidth="500"
    d:DataContext="{d:DesignInstance Type=models:WorkbenchPadItem}"
    >
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/TfsWorkbench.UIElements;Component/Resources/CommandButtonStyles.xaml"/>
                <ResourceDictionary Source="/TfsWorkbench.UIElements;component/Resources/ItemColours.xaml" />
                <ResourceDictionary Source="/TfsWorkbench.NotePadUI;component/Resources/CommonResources.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <valueConverters:HeaderTitleConverter x:Key="HeaderTitleConverter" />
            <valueConverters:BodyConverter x:Key="BodyConverter" />
            <valueConverters:OwnerConverter x:Key="OwnerConverter" />
            <valueConverters:NumericConverter x:Key="NumericConverter" />

            <Style x:Key="CollapsingTextBlock" TargetType="TextBlock">
                <Style.Triggers>
                    <Trigger Property="Text" Value="">
                        <Setter Property="Visibility" Value="Collapsed" />
                    </Trigger>
                </Style.Triggers>
            </Style>
            
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.ToolTip>
            <uiElements:WorkbenchItemToolTip WorkbenchItem="{Binding WorkbenchItem}" />
        </Grid.ToolTip>
        <Grid.ContextMenu>
            <uiElements:WorkbenchItemContextMenu
                    WorkbenchItem="{Binding WorkbenchItem}"
                    >
                <MenuItem
    				    CommandParameter="{Binding WorkbenchItem}" 
    				    Command="{x:Static uiElements:CommandLibrary.EditItemCommand}"
    				    CommandTarget="{Binding PlacementTarget, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
                        TextBlock.FontWeight="Bold"
                        >
                    <MenuItem.Icon>
                        <ContentControl Template="{StaticResource EditIconTemplate}" Style="{StaticResource MenuIconStyle}" />
                    </MenuItem.Icon>
                    <MenuItem.Header>
                        <TextBlock>
                            <TextBlock.Text>
                                <MultiBinding StringFormat="{}Edit ({0}) {1}">
                                    <Binding Path="WorkbenchItem[System.Id]" />
                                    <Binding Path="WorkbenchItem[System.WorkItemType]"/>
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>
                    </MenuItem.Header>
                </MenuItem>
                <MenuItem 
    				    Header="Open In Browser"
    				    CommandParameter="{Binding WorkbenchItem}" 
    				    Command="{x:Static uiElements:CommandLibrary.OpenItemInBrowserCommand}"
    				    CommandTarget="{Binding PlacementTarget, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
                        >
                    <MenuItem.Icon>
                        <ContentControl Template="{StaticResource WebIconTemplate}" Style="{StaticResource MenuIconStyle}" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem 
    				    Header="Save Changes"
    				    CommandParameter="{Binding WorkbenchItem}" 
    				    Command="{x:Static uiElements:CommandLibrary.SaveItemCommand}"
    				    CommandTarget="{Binding PlacementTarget, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
                        >
                    <MenuItem.Icon>
                        <ContentControl Template="{StaticResource SaveIconTemplate}" Style="{StaticResource MenuIconStyle}" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem 
    				    Header="Refresh / Reset"
    				    CommandParameter="{Binding WorkbenchItem}" 
    				    Command="{x:Static uiElements:CommandLibrary.RefreshItemCommand}"
    				    CommandTarget="{Binding PlacementTarget, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
                        >
                    <MenuItem.Icon>
                        <ContentControl Template="{StaticResource RefreshIconTemplate}" Style="{StaticResource MenuIconStyle}" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem 
    				    Header="Discard Unsaved Item"
    				    CommandParameter="{Binding WorkbenchItem}" 
    				    Command="{x:Static uiElements:CommandLibrary.DiscardItemCommand}"
    				    CommandTarget="{Binding PlacementTarget, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
                        >
                    <MenuItem.Icon>
                        <ContentControl Template="{StaticResource DeleteIconTemplate}" Style="{StaticResource MenuIconStyle}" />
                    </MenuItem.Icon>
                </MenuItem>

                <MenuItem Header="Colour">
                    <MenuItem.Icon>
                        <Rectangle Width="16" Height="16" Fill="{Binding Colour}" />
                    </MenuItem.Icon>
                    <MenuItem Header="White" Style="{StaticResource ColourSelectorMenu}" />
                    <MenuItem Header="Yellow" Style="{StaticResource ColourSelectorMenu}" />
                    <MenuItem Header="Red" Style="{StaticResource ColourSelectorMenu}" />
                    <MenuItem Header="Green" Style="{StaticResource ColourSelectorMenu}" />
                    <MenuItem Header="Blue" Style="{StaticResource ColourSelectorMenu}" />
                    <MenuItem Header="Cyan" Style="{StaticResource ColourSelectorMenu}" />
                    <MenuItem Header="Purple" Style="{StaticResource ColourSelectorMenu}" />
                    <MenuItem Header="Orange" Style="{StaticResource ColourSelectorMenu}" />
                    <MenuItem Header="Pink" Style="{StaticResource ColourSelectorMenu}" />
                </MenuItem>
                
            </uiElements:WorkbenchItemContextMenu>
        </Grid.ContextMenu>

        <Path 
			Stroke="Black" 
			Data="M0.5,0.5 L499.5,0.5 496.66667,232 495.33334,296 72.667009,296.66667 0.5,299.5 C0.5,227.55556 -0.58082467,105.49097 1.5,98 4,89 0.5,28.222222 0.5,0.5 z" 
            Fill="{Binding Path=Colour, Converter={StaticResource ColourPicker}}"
            Stretch="Fill"
            >
            <Path.Effect>
                <DropShadowEffect Opacity="0.5" />
            </Path.Effect>
        </Path>

        <Viewbox Stretch="Fill" VerticalAlignment="Top" HorizontalAlignment="Stretch" Margin="15,0,15,30">
            <Grid>
                <Rectangle Height="1" Margin="0,42,0,0" Stroke="#ff0000ff" VerticalAlignment="Top" />

                <Rectangle Height="1" Margin="0,80, 0,0" Stroke="#ffa5a5a5" VerticalAlignment="Top" />
                <Rectangle Height="1" Margin="0,110,0,0" Stroke="#ffa5a5a5" VerticalAlignment="Top" />
                <Rectangle Height="1" Margin="0,140,0,0" Stroke="#ffa5a5a5" VerticalAlignment="Top" />
                <Rectangle Height="1" Margin="0,170,0,0" Stroke="#ffa5a5a5" VerticalAlignment="Top" />
                <Rectangle Height="1" Margin="0,200,0,0" Stroke="#ffa5a5a5" VerticalAlignment="Top" />
                <Rectangle Height="1" Margin="0,230,0,0" Stroke="#ffa5a5a5" VerticalAlignment="Top" />
                <Rectangle Height="1" Margin="0,260,0,0" Stroke="#ffa5a5a5" VerticalAlignment="Top" />
            </Grid>
        </Viewbox>

        <Grid Margin="15">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <TextBlock 
                TextWrapping="NoWrap"
                TextTrimming="CharacterEllipsis"
                FontWeight="Bold" 
                FontSize="22" 
                >
                <TextBlock.Text>
                    <MultiBinding Converter="{StaticResource HeaderTitleConverter}">
                        <Binding Path="WorkbenchItem[System.State]" />
                        <Binding Path="WorkbenchItem" />
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>

            <TextBlock 
                Grid.Row="1"
                FontSize="18">
                <TextBlock 
                    FontWeight="Bold"
                    Text="{Binding Path=WorkbenchItem[System.State]}"
                    />
                <TextBlock 
                    FontStyle="Italic" 
                    Text="{Binding Path=WorkbenchItem[System.WorkItemType], StringFormat={}({0})}"
                    />
            </TextBlock>

            <TextBlock 
                Grid.Row="2"
                TextWrapping="Wrap" 
                TextTrimming="CharacterEllipsis"
                FontSize="16"
                >
                <TextBlock.Text>
                    <MultiBinding Converter="{StaticResource BodyConverter}">
                        <Binding Path="WorkbenchItem[System.State]" />
                        <Binding Path="WorkbenchItem" />
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>

            <Grid Grid.Row="3">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0.7*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBlock 
                    TextWrapping="NoWrap" 
                    TextTrimming="CharacterEllipsis"
                    Style="{StaticResource CollapsingTextBlock}"
                    VerticalAlignment="Bottom"
                    FontSize="14"
                    >
                    <TextBlock.Text>
                        <MultiBinding Converter="{StaticResource OwnerConverter}">
                            <Binding Path="WorkbenchItem[System.State]" />
                            <Binding Path="WorkbenchItem" />
                        </MultiBinding>
                    </TextBlock.Text>
                </TextBlock>

                <TextBlock 
                    Grid.Column="1" 
                    TextWrapping="NoWrap" 
                    TextTrimming="CharacterEllipsis"
                    FontSize="32"
                    FontWeight="Bold"
                    TextAlignment="Right"
                    Foreground="DarkRed"
                    FontFamily="Lucida Handwriting"                    
                    Style="{StaticResource CollapsingTextBlock}"
                    >                    
                    <TextBlock.Text>
                        <MultiBinding Converter="{StaticResource NumericConverter}">
                            <Binding Path="WorkbenchItem[System.State]" />
                            <Binding Path="WorkbenchItem" />
                        </MultiBinding>
                    </TextBlock.Text>
                </TextBlock>

            </Grid>
        </Grid>
    </Grid>
</UserControl>
